<template>
  <div class="dashboard-container">
    <div class="app-container">
      <el-card>
        <el-tabs>
          <el-tab-pane label="用户管理">
            <el-form ref="ruleForm" :model="ruleForm" status-icon :rules="rules" label-width="100px" class="demo-ruleForm">
              <el-form-item label="用户名" style="width:50%" prop="username">
                <el-input v-model="ruleForm.username" autocomplete="off" />
              </el-form-item>
              <el-form-item label="密码" style="width:50%" prop="newpossword">
                <el-input v-model="ruleForm.newpossword" type="password" />
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click="btnOk">更新</el-button>
              </el-form-item>
            </el-form>
          </el-tab-pane>
          <el-tab-pane label="个人信息">
            <user-info />
          </el-tab-pane>
          <el-tab-pane label="岗位信息">
            <job-info />
          </el-tab-pane>
        </el-tabs>
      </el-card>
    </div>
  </div>
</template>

<script>
import userInfo from '@/views/employees/components/user-info.vue'
import jobInfo from '@/views/employees/components/job-info.vue'
import { ByIdgetUser, saveUserDetailById } from '@/api/employee'
export default {
  components: {
    userInfo,
    jobInfo
  },
  data() {
    return {
      ruleForm: {
        username: '',
        newpossword: ''
      },
      rules: {
        username: [{ required: true, message: '用户名不能未空', trigger: 'blur' }],
        newpossword: [{ required: true, message: '密码不能为空', trigger: 'blur' }, {
          max: 16, min: 3, message: '密码长度3-16位', trigger: 'blur'
        }]
      }
    }
  },
  mounted() {
    this.PersonalInfo()
  },
  methods: {
    async  PersonalInfo() {
      const res = await ByIdgetUser(this.$route.params.id)
      this.ruleForm = res
    },
    async btnOk() {
      await saveUserDetailById({ ...this.ruleForm, password: this.ruleForm.newpossword })
      this.$message.success('修改成功')
      this.PersonalInfo()
    }
  }
}
</script>

<style>

</style>
